MyDesktop.OutputStorageWindow = Ext.extend(Ext.app.Module, {
    id:'outStorage-win',
    init : function(){
        this.launcher = {
            text: '出库管理',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

	record : Ext.data.Record.create([
        	{name : 'docID',mapping : 'docID',type : 'string'}, 
        	{name : 'pid',mapping : 'fid',type : 'int'}, 
        	{name : 'buyer',mapping : 'buyer',type : 'string'}, 
        	{name : 'unit',mapping : 'unit',type : 'string'}, 
        	{name : 'mobile',mapping : 'mobile',type : 'string'}, 
        	{name : 'phone',mapping : 'phone',type : 'string'}, 
        	{name : 'address',mapping : 'address',type : 'string'}, 
        	{name : 'csum',mapping : 'csum',type : 'float'},  
        	{name : 'loanid',mapping : 'loanid',type : 'int'}, 
        	{name : 'loanname',mapping : 'loanname',type : 'string'},  
        	{name : 'rate',mapping : 'rate',type : 'float'}, 
        	{name : 'interest',mapping : 'interest',type : 'float'},
        	{name : 'charge',mapping : 'charge',type : 'float'},
        	{name : 'debtorid',mapping : 'debtorid',type : 'int'},
        	{name : 'debtorname',mapping : 'debtorname',type : 'string'},
        	{name : 'startdate',mapping : 'startdate',type : 'date'},
        	{name : 'closedate',mapping : 'closedate',type : 'date'},
        	{name : 'accountid',mapping : 'accountid',type : 'int'},
        	{name : 'accountname',mapping : 'accountname',type : 'string'},
        	{name : 'status',mapping : 'status',type : 'string'},
			{name : 'createMan',mapping : 'createMan',type : 'string'},
        	{name : 'createtime',mapping : 'createtime',type : 'string'},
        	{name : 'memo',mapping : 'memo',type : 'string'}
	]),
	
	cm : new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), 
         new Ext.grid.CheckboxSelectionModel({singleSelect : false}),
         {header : '业务单据',width : 120,dataIndex : 'docID'},
		 {header : '业务单位',width : 120,dataIndex : 'unit'},
		 {header : '用户姓名',width : 120,dataIndex : 'buyer'},
		 {header : '手机',width : 90,dataIndex : 'mobile'},
		 {header : '联系电话',width : 80,dataIndex : 'phone'},
		 {header : '用户地址',width : 90,dataIndex : 'address'},
		 {header : '报修日期',width : 90,dataIndex : 'closedate',sortable:true},
		 {header : '送货日期',width : 90,dataIndex : 'closedate',sortable:true},
		 {header : '维修日期',width : 80,dataIndex : 'csum',sortable : false},
		 {header : '级别',width : 60,dataIndex : 'rate',sortable : true},
		 {header : '状态',width : 60,dataIndex : 'status',sortable : true},
		 {header : '录入人员',width : 60,dataIndex : 'createMan'}
	]),
	
    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('outStorage-win');
		
        if(!win){
		
		var store=new Ext.data.Store({
        	url : app.url+'/admin/repair/findList.do',
			baseParams:{start:0,limit:20},
        	reader : new Ext.data.JsonReader({totalProperty : 'totalProperty',root : 'root'}, 
        	this.record)
        });
		
		var ds_debit_data = new Ext.data.Store({
        	url : app.url+'/admin/repair/repairInfo.do',
        	reader : new Ext.data.JsonReader({root : 'root'}, 
            this.record)
        });
		
	  
	   var stock_form = new Ext.FormPanel({
	            title : '',
            	border : true,
				region: 'north',
                labelAlign : 'right',
                labelWidth : 60,
				frame : true,
				height: 85,
            	items : [{
						  layout:'column',
						  items:[{
        						  columnWidth : .3,
        						  layout : 'form',
        						  items : [getEmployeeCombo('申领人')]
								    },{
        								columnWidth : .3,
        								layout : 'form',
        								items : [{xtype : 'datefield',fieldLabel : '申领日期',name : 'buyDate',anchor : '100%',allowBlank : false,format:'Y-m-d'}]
								    }]
							}]
						});
						
						
	   var grid_stock = new Ext.grid.GridPanel({
        	title : '库存',
        	iconCls : 'icon-grid',
        	collapsible: false,
			border:false,
            region: 'center',
            margins: '5 0 0 0',
			columnLines :true,
			autoScroll : true,
			width : 600,
        	viewConfig:
        	{
        	 forceFit:false,
        	 scrollOffset:15
        	 },	   	   
        	autoWidth : true,
        	region : 'center',
        	cm : this.cm,
        	ds : store,
        	sm : new Ext.grid.CheckboxSelectionModel({singleSelect : false}),
        	enableColumnMove : false,
        	trackMouseOver : false,
        	frame : true,
        	clicksToEdit : 1
        });	
		

		var p_west = {
            layout: 'border',
            bodyBorder: false,
            defaults: {
                split: true,
                animFloat: false,
                autoHide: false,
                useSplitTips: true,
        		margins: '5 0 0 0',
                cmargins: '5 5 0 0'
            },
            items: [stock_form,grid_stock]
        };

	   var sale_form = new Ext.FormPanel({
	            title : '出库',
            	border : true,
				region: 'north',
                labelAlign : 'right',
                
				frame : true,
				height: 110,
            	items : [{
						  layout:'column',
						  items:[{
        						  columnWidth : .5,
        						  layout : 'form',
        						  labelWidth : 40,
        						  items : [getEmployeeCombo('申领人')]
								    },{
        								columnWidth : .5,
        								layout : 'form',
        								labelWidth : 60,
        								items : [{xtype : 'datefield',fieldLabel : '申领日期',name : 'buyDate',anchor : '100%',allowBlank : false,format:'Y-m-d'}]
								    }]
							},{// 4 row
									layout:'column',
									items:[{
        								columnWidth : 1,
        								layout : 'form',
        								labelWidth : 30,
        								items : [{xtype : 'textarea',fieldLabel : '备注',name : 'remarks',anchor : '100%',height: 48}]
								    }]
							}]
						});
		
	   var grid_debit = new Ext.grid.EditorGridPanel({
        	title : '出库条目',
        	iconCls : 'icon-grid',
        	collapsible: false,
			border:false,
            region: 'center',
            margins: '5 0 0 0',
			columnLines :true,
			autoScroll : true,
			width : 600,
        	viewConfig:
        	{
        	 forceFit:false,
        	 scrollOffset:15
        	 },	   	   
        	autoWidth : true,
        	region : 'center',
        	cm : this.cm,
        	ds : store,
        	sm : new Ext.grid.CheckboxSelectionModel({singleSelect : false}),
        	enableColumnMove : false,
        	trackMouseOver : false,
        	frame : true,
        	clicksToEdit : 1
        });	
		
		
		var tb = new Ext.Toolbar({
        height: 35,
		region: 'south',
		buttonAlign : 'center',
        items: [{
        	 xtype: 'button',
             text: '保存'
             },'-',{
        	 xtype: 'button',
             text: '保存'
             },'-',{
        	 xtype: 'button',
             text: '保存'
             }]
     });

		var p_debit = {
            layout: 'border',
            bodyBorder: false,
            defaults: {
                split: true,
                animFloat: false,
                autoHide: false,
                useSplitTips: true,
        		margins: '5 0 0 0',
                cmargins: '5 5 0 0'
            },
            items: [sale_form,grid_debit,tb]
        };

        var nav = new Ext.Panel({
                region: 'west',
                title: '库存查询',
                split: true,
                width: 500,
                minSize: 175,
                maxSize: 500,
				layout : 'card',
				border : false,
                activeItem : 0,
                collapsible: true,
                margins: '0 0 0 5',
                items: [p_west]
        });
        var vp = new Ext.Panel({
				region: 'center',
                deferredRender: false,
				layout : 'card',
				border : false,
                activeItem : 0,
				items : [p_debit]
			
        });
		

            win = desktop.createWindow({
                id: 'outStorage-win',
                title:'出库管理',
                width:1000,
                height:530,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
                layout: 'border',
                items:[nav,vp]
                    
            });
        }
        win.show();
    }
});